local sk__guhuo = fk.CreateSkill {

  name = "sk__guhuo",

  tags = {  },

}



sk__guhuo:addEffect(fk.TurnStart, {
  name = "sk__guhuo",
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__guhuo.name) and target ~= player and not target.dead and player:canPindian(target)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__guhuo.name, data, "#sk__guhuo-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    local pindian = player:pindian({target}, sk__guhuo.name)
    if pindian.results[target].winner == player then
      if not player.dead and not target.dead then
        if player:getMark("sk__guhuo_cards") == 0 then
          room:setPlayerMark(player, "sk__guhuo_cards", U.getUniversalCards(room, "bt"))
        end
        room:setPlayerMark(player, "sk__guhuo_target", target.id)
        local success, dat = room:askForUseActiveSkill(player, "sk__guhuo_active", "#sk__guhuo-choose::"..target.id, false)
        room:setPlayerMark(player, "sk__guhuo_target", 0)
        if success and dat then
          local card = Fk:cloneCard(Fk:getCardById(dat.cards[1]).name)
          card.skillName = sk__guhuo.name
          room:useCard{
            from = target,
            tos = table.map(dat.targets, Util.Id2PlayerMapper),
            card = card,
          }
        end
      end
    else
      if not player.dead then
        room:damage{
          from = target,
          to = player,
          damage = 1,
          skillName = sk__guhuo.name,
        }
      end
    end
  end
})

return sk__guhuo